package pres.wchen.bussiness.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import pres.wchen.bussiness.cor.model.BaseModel;
import pres.wchen.bussiness.service.BusInfoService;
import pres.wchen.bussiness.vo.BusAccountVO;
import pres.wchen.bussiness.service.BusAccountService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import pres.wchen.bussiness.vo.BusInfoVO;
import pres.wchen.bussiness.web.BaseController;

/**
 * @作者： wchen
 * @描述： 商户账号表管理
 * @创建时间： 2018/03/04 17:21:51
 * @版本：Copyright 2018, Inc. All Rights Reserved.
 * @修改信息：
 */
@RestController
@RequestMapping("/bus/account")
public class BusAccountController extends BaseController {
	@Autowired
	private BusAccountService busAccountService;

	@Autowired
	private BusInfoService busInfoService;


	/**
     *  @描述: 商户账号表新增
     *  @参数： [busAccountVO]
     *  @返回值： java.util.Map
     *  @创建人: wchen
     *  @创建时间: 2018/3/04
     *  @修改人和其它信息:
     */
	@PostMapping(value = "/add")
	public Map insert(BusAccountVO busAccountVO) {
		Long id = busAccountService.insert(busAccountVO);
		return super.dealInsertResult(id);
	}


	/**
     *  @描述: 商户账号表删除
     *  @参数： [id]
     *  @返回值： java.util.Map
     *  @创建人: wchen
     *  @创建时间: 2018/3/04
     *  @修改人和其它信息:
     */
	@DeleteMapping(value = "/delete/{id}")
	public Map delete(@PathVariable("id") Long id) {
		Integer result = busAccountService.delete(id);
		return super.dealDeleteResult(result);
	}


	/**
     *  @描述: 商户账号表修改
     *  @参数： [busAccountVO]
     *  @返回值： java.util.Map
     *  @创建人: wchen
     *  @创建时间: 2018/3/04
     *  @修改人和其它信息:
     */
	@PutMapping(value = "/modify/")
	public Map modify(BusAccountVO busAccountVO) {
		Integer result = busAccountService.update(busAccountVO);
		return super.dealUpdateResult(result);
	}


	/**
     *  @描述: 商户账号表详情
     *  @参数： [id]
     *  @返回值： java.util.Map
     *  @创建人: wchen
     *  @创建时间: 2018/3/04
     *  @修改人和其它信息:
     */
	@GetMapping(value = "/info/{id}")
	public ModelAndView info(@PathVariable("id") Long id) {
	    Map conditionMap = new HashMap();
        conditionMap.put("id", id);
		BusAccountVO busAccountVO = busAccountService.info(conditionMap);
		return super.dealInfoResult("/bus/business/account/maintain_modify", busAccountVO);
	}


	/**
     *  @描述: 商户账号表分页列表
     *  @参数： [request]
     *  @返回值： java.util.Map
     *  @创建人: wchen
     *  @创建时间: 2018/3/04
     *  @修改人和其它信息:
     */
	@GetMapping(value = "/pageList")
	public ModelAndView pageList(HttpServletRequest request) {
		Object busId = request.getParameter("busId");
		Object busName = request.getParameter("busName");
		Object pageSize = request.getParameter("pageSize");
		Object pageNo = request.getParameter("pageNo");
		Object accUsername = request.getParameter("accUsername");
		Object pageFlag = request.getParameter("pageFlag");
		Map conditionMap = new HashMap();
		conditionMap.put("pageSize", pageSize);
		conditionMap.put("pageNo", pageNo);
		conditionMap.put("accUsername", accUsername);
		conditionMap.put("busId", busId);
		conditionMap.put("pageFlag", pageFlag);
		BaseModel baseModel = busAccountService.list(conditionMap);
		//商户id 商户name
		Map<String, String> remarkMap = new HashMap<>();
		remarkMap.put("busId", busId.toString());
		remarkMap.put("busName", busName.toString());

		//访问地址
		conditionMap.clear();
		conditionMap.put("id", busId);
		BusInfoVO busInfoVO = busInfoService.info(conditionMap);
		remarkMap.put("visitUrl", busInfoVO.getVisitUrl());
		baseModel.setRemark(remarkMap);
		return super.dealListResult("/bus/business/account/maintain", baseModel);
	}

}
